package com.xqls.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xqls.bean.LevelTimeBean;
import com.xqls.biz.DictionaryBiz;
import com.xqls.biz.MessageBiz;
import com.xqls.util.CommonPage;
import com.xqls.util.CommonResult;
import com.xqls.util.DictionaryEnums;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequestMapping(value = "/message")
@Controller
public class MessageController {

	@Autowired private MessageBiz messageBiz;
	@Autowired private DictionaryBiz dictionaryBiz;
	
	@RequestMapping(value = "/index")
	public ModelAndView index(){
		ModelAndView view = new ModelAndView("message/messageIndex");
		Map<Integer, String> alarmTypeMap = dictionaryBiz.queryDictionaryByParent(
			  DictionaryEnums.ALARM_TYPE.getCode());
		view.addObject("alarmTypeMap", alarmTypeMap);
		return view;
	}
	
	@RequestMapping(value = "/messageListData")
	@ResponseBody
	public CommonResult messageListData(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response){
		CommonResult result = messageBiz.queryByCommpage(commonPage,request,response);
		if(result.getIsSuccess()){
			result.setData(commonPage);
		}
		return result;
	}
	
	@RequestMapping(value = "/messageSetTime")
	public ModelAndView messageSetTime(){
		ModelAndView view = new ModelAndView("message/messageSetTime");
		LevelTimeBean level = messageBiz.getLevelTime();
		view.addObject("level", level);
		return view;
	}
	
	@RequestMapping(value = "/saveTime")
	@ResponseBody
	public CommonResult saveTime(LevelTimeBean bean){
		CommonResult result = messageBiz.setLevelTime(bean);
		return result;
	}
}
